Skip to content

feat(xref): move term autocomplete from client to server#511

Closed
marcoscaceres wants to merge 6 commits into
mainfrom
feat/server-autocomplete
Closed

feat(xref): move term autocomplete from client to server#511
marcoscaceres wants to merge 6 commits into
mainfrom
feat/server-autocomplete

Conversation

@marcoscaceres

@marcoscaceres marcoscaceres commented May 3, 2026

Copy link
Copy Markdown
Collaborator
  • Adds GET /xref/meta/terms/search?q=<query>&limit=<n> endpoint
  • Binary search for prefix matches + linear scan infix fallback on a pre-sorted 22K terms array
  • Case-insensitive matching, original-case results, 24h cache
  • Client drops the 483KB terms download; autocomplete uses 150ms-debounced server fetch instead
  • Existing /xref/meta/terms endpoint unchanged (backward compatible)
  • 12 unit tests for the search logic

Closes #226

Landing order: land last of the xref trio (#497, #529, #511) and rebase onto main after #529; all three edit static/xref/script.js. Suggested batch order: #499, #500, #501, #497, #529, #511 (#424 independent).

Comment thread routes/xref/terms.get.ts Fixed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR moves xref term autocomplete from the browser to the server by adding a dedicated term-search endpoint and updating the xref page to query it on demand instead of downloading the full term list up front. That fits the xref codebase’s existing split between server-side route handlers and a thin browser UI, and targets the payload-size problem described in #226.

Changes:

  • Add a new GET /xref/meta/terms/search endpoint with cached, case-insensitive term lookup over a prebuilt index.
  • Update the xref client to stop requesting the full terms payload and instead fetch debounced autocomplete suggestions from the new endpoint.
  • Add route-level tests for the new term-search behavior; also align one baseline background worker type import with the existing worker-queue pattern.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/routes/xref/terms.test.js Adds unit tests covering new server-side xref term search behavior.
static/xref/script.js Switches autocomplete from client-side Fuse search to debounced server fetches and trims initial metadata fetch.
routes/xref/terms.get.ts Introduces the new xref term search endpoint and in-memory sorted term index.
routes/xref/index.ts Wires the new /meta/terms/search route into the xref router.
routes/api/baseline/update.ts Updates the worker module type import to match the existing typed background-task-queue pattern.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread routes/xref/terms.get.ts Outdated
Comment thread static/xref/script.js
@marcoscaceres
marcoscaceres requested a review from sidvishnoi June 30, 2026 04:46
marcoscaceres and others added 5 commits June 30, 2026 15:45
Add GET /xref/meta/terms/search?q=<query>&limit=<n> endpoint using
binary search for prefix matches with infix fallback on a pre-sorted
terms array. Case-insensitive matching, original-case results.

Client no longer downloads 483KB of terms on page load. Instead,
the autocomplete debounces at 150ms and fetches 15 suggestions
per keystroke. The existing /xref/meta/terms endpoint is unchanged.

Closes #226

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add .catch() and r.ok check to the client fetch so network errors
and non-JSON responses degrade gracefully to an empty suggestion
list. Add test verifying prefix matches precede infix-only matches.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Normalize req.query.q to a string when Express parses repeated
?q= params as an array. Remove the unused terms reference from
the metadata object that would throw a ReferenceError.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Express parses repeated ?q= query parameters as arrays at runtime,
which would crash searchTerms() since arrays lack toLowerCase().
Add tests verifying array params are normalized to the first element.
req.query.limit can be a string[] (repeated param); the q param already handles that but limit did not, and its type understated it. Normalize to the first value.
@marcoscaceres
marcoscaceres force-pushed the feat/server-autocomplete branch from dd311c4 to 85e6d67 Compare June 30, 2026 05:49
@marcoscaceres

Copy link
Copy Markdown
Collaborator Author

@sidvishnoi, I need to more thoroughly check the performance of this one. I'll reopen it once I do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Move autocomplete to server

3 participants